package Aleehot100;

/**
 * ClassName: c078
 * Package: Aleehot100
 * Description:55. 跳跃游戏
 *
 * @Author BCXJ
 * @Create 2025/9/3 08:49
 * @Version 1.0
 * @Since 1.0
 */
public class c078 {
    public static void main(String[] args) {
        int[] arr = {3,2,1,1,4};
        System.out.println(canJump(arr));
    }
    public static boolean canJump(int[] nums) {
        int reachMax = 0;
        for (int curIndex = 0; curIndex < nums.length; curIndex++) {
            // 当前index > 可达最远
            if(curIndex > reachMax) {
                return false;
            }
            // 可达最远位置更新
            reachMax = Math.max(reachMax, curIndex + nums[curIndex]);
            if(reachMax >= nums.length - 1) {
                return true;
            }
        }


        return false;
    }

}
